﻿@using TD.Common.Kendo.Mvc5.Grid
@using TD.CTS.WebUI.Models

@model TD.CTS.Data.Entities.Trial

@section head{
    <link href="@Url.Content("~/Content/td/td.kendo.grid.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/td/td.kendo.tabstrip.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/td/td.kendo.grid.js")"></script>

    <style type="text/css">
        .td-textarea-edit{
            width: 300px !important;
            height: 100px !important;
        }
    </style>
}

@{
    var isNew = ViewBag.IsNew;
    var tab = ViewBag.Tab == null ? TrialTab.Main : (TrialTab)ViewBag.Tab;
}

@if (isNew)
{
    <div id="MainContent" style="overflow:auto;" class="k-content k-state-active">
        @Html.Partial("EditorTemplates/MainEditor")
    </div>
    <script>
        $(document).ready(function () {
            SetContentBlock($("#MainContent"));
        });

        $(window).bind("resize", function () {
            SetContentBlock($("#MainContent"));
        });
    </script>
}
else
{ 
    @(Html.Kendo().TabStrip()
        .Name("TabStrip")
        .Animation(false)
        //.Events(events => events.Show("ShowTab"))
        .Items(tabs =>
            {
                var trialCode = Model.Code ?? "";
                var tabBuilder = tabs.Add().Text("Основное");
                if (tab == TrialTab.Main)
                {
                    tabBuilder.Selected(true).Content(@<text>@Html.Partial("EditorTemplates/MainEditor")</text>);
                }
                else
                    tabBuilder.Action("Edit", "Trials", new { Id = Model.Code, VersionId = Model.Version, Tab = TrialTab.Main });

                tabBuilder = tabs.Add().Text("Материалы");
                if (tab == TrialTab.Materials)
                {
                    tabBuilder.Selected(true).ContentHtmlAttributes(new { style = "padding:0;" })
                    .Content(@<text>@Html.Partial("EditorTemplates/MaterialsEditor", trialCode)</text>);
                }
                else
                    tabBuilder.Action("Edit", "Trials", new { Id = Model.Code, VersionId = Model.Version, Tab = TrialTab.Materials });

                tabBuilder = tabs.Add().Text("Визиты");
                if (tab == TrialTab.Visits)
                {
                    tabBuilder.Selected(true).ContentHtmlAttributes(new { style = "padding:0;" })
                    .Content(@<text>@Html.Partial("EditorTemplates/ProceduresEditor", Model)</text>);
                }
                else
                    tabBuilder.Action("Edit", "Trials", new { Id = Model.Code, VersionId = Model.Version, Tab = TrialTab.Visits });

                tabBuilder = tabs.Add().Text("Роли");
                if (tab == TrialTab.Roles)
                {
                    tabBuilder.Selected(true).ContentHtmlAttributes(new { style = "padding:0;" })
                    .Content(@<text>@Html.Partial("EditorTemplates/RolesEditor", Model)</text>);
                }
                else
                    tabBuilder.Action("Edit", "Trials", new { Id = Model.Code, VersionId = Model.Version, Tab = TrialTab.Roles });
                    
                @*tabs.Add().Text("Стоимость визитов")
                    .ContentHtmlAttributes(new { style = "padding:0;" })
                    .Content(@<text>@Html.Partial("EditorTemplates/VisitCostsEditor", trialCode)</text>)
                    .Enabled(!isNew);
                tabs.Add().Text("Статьи доходов")
                    .ContentHtmlAttributes(new { style = "padding:0;" })
                    .Content(@<text>@Html.Partial("EditorTemplates/IncomeArticlesEditor", trialCode)</text>)
                    .Enabled(!isNew);*@
            }
        )
    )

    @(Html.Kendo().Notification()
        .Name("SaveNotification")
        .Position(p => p.Pinned(true).Top(115).Right(30))
        .Width(150)
    )

    <script>
        $(document).ready(function () {
            SetContentBlock($("#TabStrip .k-content"));
        });

        $(window).bind("resize", function () {
            var tabStrip = $("#TabStrip").data("kendoTabStrip");
            var tab = tabStrip.select();
            var index = tab.index();
            if (index === 1 || index === 2 || index === 3) {
                var conteiner = tabStrip.contentElements[0];
                StretchGrid($(conteiner), $(conteiner).find(".k-grid"));
            }
        });
    </script>
}